//
// Created by Zeppyrz on 2025/11/7.
//

#ifndef ZEDISK_DOWNLOADTASK_H
#define ZEDISK_DOWNLOADTASK_H

#include <fstream>
#include <functional>

#include "CommonTask.h"

namespace ZeDiskGUI {

class DECLSPEC DownLoadTask : public ZeDisk::CommonTask {
 public:
  using DownloadCompleteCallback = std::function<void()>;
  void HandleMessage(const ZeDisk::Message* msg) override;
  void HandleRawMessage(void* data, int size) override;
  void ConnectCallback() override;
  void HandleDownloadAccept(const ZeDisk::Message* msg);

  bool Stop() override;

  [[nodiscard]] std::string& file_name() { return file_name_; }
  [[nodiscard]] std::string& local_file_path() { return local_file_path_; }

  /**
   * @brief 下载完毕回调
   */
  DownloadCompleteCallback download_complete_callback_;

 private:
  std::string file_name_;
  std::ofstream outfile_;
  int download_size_ = 0;  // 客户端已经下载的文件大小
  int file_size_ = 0;
  std::string local_file_path_;
};

}  // namespace ZeDiskGUI

#endif  // ZEDISK_DOWNLOADTASK_H
